package maze.view;

import maze.app.Maze;
import maze.model.Pair;

import org.lwjgl.opengl.GL11;

public abstract class Sprite
{
	public Pair pos;

	protected float width;
	protected float height;

	protected int entityTexture;
	protected int maskTexture;

	public Sprite(String name)
	{
		pos = new Pair();

		width = Maze.UNIT;
		height = Maze.UNIT;

		entityTexture = Texture.loadTexture(name);
		maskTexture = Texture.loadTexture(name + "_mask");
	}

	public abstract void init();

	public void drawTexture()
	{
		// bind to the appropriate texture for this sprite
		GL11.glBlendFunc(GL11.GL_DST_COLOR, GL11.GL_ZERO);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, maskTexture);
		// GL11.glColor4f(0, 0, 0, 0.5f);

		// draw the texture
		GL11.glBegin(GL11.GL_QUADS);
		{
			GL11.glTexCoord2f(0, 0);
			GL11.glVertex2f(-width / 2, -height / 2);

			GL11.glTexCoord2f(0, 1);
			GL11.glVertex2f(-width / 2, height / 2);

			GL11.glTexCoord2f(1, 1);
			GL11.glVertex2f(width / 2, height / 2);

			GL11.glTexCoord2f(1, 0);
			GL11.glVertex2f(width / 2, -height / 2);
		}
		GL11.glEnd();

		// bind to the appropriate texture for this sprite
		GL11.glBlendFunc(GL11.GL_ONE, GL11.GL_ONE);
		GL11.glBindTexture(GL11.GL_TEXTURE_2D, entityTexture);

		// draw the texture
		GL11.glBegin(GL11.GL_QUADS);
		{
			GL11.glTexCoord2f(0, 0);
			GL11.glVertex2f(-width / 2, -height / 2);

			GL11.glTexCoord2f(0, 1);
			GL11.glVertex2f(-width / 2, height / 2);

			GL11.glTexCoord2f(1, 1);
			GL11.glVertex2f(width / 2, height / 2);

			GL11.glTexCoord2f(1, 0);
			GL11.glVertex2f(width / 2, -height / 2);
		}
		GL11.glEnd();
	}

	public abstract void render();
}
